package com.ydd.common.result;


import com.ydd.common.exception.ErrRespCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
@NoArgsConstructor
public class ResponseResult<T> implements Serializable {
    @ApiModelProperty(value = "状态码")
    private int code;
    @ApiModelProperty(value = "响应消息")
    private String msg;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseResult<T> result(int code, String msg, T data) {
        return new ResponseResult<T>(code, msg, data);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<T>(SuccessRespCode.Ok.getValue(), SuccessRespCode.Ok.getName(), null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>(SuccessRespCode.Ok.getValue(), SuccessRespCode.Ok.getName(), data);
    }


    public static <T> ResponseResult<T> error(String msg) {
        return new ResponseResult<T>(ErrRespCode.REQUEST_ERROR.getValue(), msg, null);
    }

    public static <T> ResponseResult<T> error(int code, String msg) {
        return new ResponseResult<T>(code, msg, null);
    }

}
